from rest_framework.generics import ListAPIView
from .models import CourseCategory
from .serializers import CourseCategoryModelSerializer


class CourseCategoryListAPIView(ListAPIView):
    """
    课程分类
    """
    queryset = CourseCategory.objects.filter(is_show=True, is_deleted=False).order_by("orders")
    serializer_class = CourseCategoryModelSerializer


from .models import Course
from .serializers import CourseModelSerializer
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import OrderingFilter
from .pagination import CoursePageNumberPagination

# class CourseListAPIView(ListAPIView):
#     queryset = Course.objects.filter(is_show=True, is_deleted=False).order_by("orders")
#     serializer_class = CourseModelSerializer

"""
课程列表
"""


class CourseListAPIView(ListAPIView):
    queryset = Course.objects.filter(is_show=True, is_deleted=False).order_by("orders")
    serializer_class = CourseModelSerializer
    filter_backends = [DjangoFilterBackend, OrderingFilter]
    filter_fields = ('course_category',)  # [过滤]与models里的外键名一致 并不是数据库中的字段名
    ordering_fields = ('id', 'students', 'price')  # [排序]
    pagination_class = CoursePageNumberPagination


from rest_framework.generics import RetrieveAPIView
from .serializers import CourseRetrieveSerializer

"""
课程详情
"""


class CourseRetrieveAPIView(RetrieveAPIView):
    queryset = Course.objects.filter(is_show=True, is_deleted=False)
    serializer_class = CourseRetrieveSerializer


from .models import CourseChapter
from .serializers import CourseChapterModelSerializer

"""
课程章节
"""


class CourseChapterListAPIView(ListAPIView):
    queryset = CourseChapter.objects.filter(is_show=True, is_deleted=False).order_by("orders", "id")
    serializer_class = CourseChapterModelSerializer
    filter_backends = [DjangoFilterBackend]
    filter_fields = ('course',)  # [过滤]与models里的外键名一致 并不是数据库中的字段名
